using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DslEditorPowerToy.Controls;
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Diagrams;
using Microsoft.VisualStudio.EnterpriseTools.OperationDesigner;
using Microsoft.VisualStudio.VirtualTreeGrid;
using Microsoft.VisualStudio.Modeling.Shell;

namespace EastBancTech.InstallerDefinition.DslEditors.Controls
{
    public partial class FileSourceCtrl : UserControl, IMonitorSelection, ISelectionProvider, IOperationDesignerColumnHost
    {
        ITree treeProvider;

        public FileSourceCtrl()
        {
            InitializeComponent();

            this.treeProvider = new VariableColumnTree(2);
            
            this.virtualTreeControl1.SelectionMode = SelectionMode.One;
            this.virtualTreeControl1.LabelEditSupport = VirtualTreeLabelEditActivationStyles.ImmediateMouse | VirtualTreeLabelEditActivationStyles.Explicit;
            this.virtualTreeControl1.HasGridLines = true;
            this.virtualTreeControl1.ShowToolTips = false;
            this.virtualTreeControl1.MultiColumnTree = this.treeProvider as IMultiColumnTree;
            this.virtualTreeControl1.IsDragSource = false;
            this.virtualTreeControl1.MultiColumnHighlight = true;

        }

        #region IMonitorSelection Members

        public void NotifySelectionChanged(ISelectionProvider selectionProvider, SelectionChangeSource source)
        {
            if ((SelectionChangeSource.Diagram == source) &&
                ((selectionProvider != null) && (null != selectionProvider.PrimarySelection)))
            {
                ShapeElement selectedElement = (selectionProvider.PrimarySelection as ShapeElement);
                if (selectedElement.ModelElement is EastBancTech.InstallerDefinition.Component)
                {
                    EastBancTech.InstallerDefinition.Component component = selectedElement.ModelElement as EastBancTech.InstallerDefinition.Component;
                    this.propertyGrid1.SelectedObject = component.FileSource;
                    FillTree(component);
                }
            }
        }

        private void FillTree(Component component)
        {
            ComponentHeaderBranch branch = new ComponentHeaderBranch();
            branch.Initialize(component, new Microsoft.VisualStudio.EnterpriseTools.OperationDesigner.ColumnDescriptor[] { new FileActionColumn(), new NameColumn()});
            this.virtualTreeControl1.Tree.Root = branch;
        }

        #endregion

        #region ISelectionProvider Members

        public System.Collections.ICollection GetSelectedComponents()
        {
            return null;
        }

        public object PrimarySelection
        {
            get { return null; }
        }

        public int SelectionCount
        {
            get { return 0; }
        }

        #endregion

        private void dataGridView1_UserAddedRow(object sender, DataGridViewRowEventArgs e)
        {

        }

        #region IOperationDesignerColumnHost Members

        public void Refresh(object tracking)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public bool InLabelEdit
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }
        public Store Store
        {
            get
            {
                return null;
            }
        }


        #endregion

        #region IServiceProvider Members

        public object GetService(Type serviceType)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion
    }
}
